package cn.edu.cqytxy.service;

import cn.edu.cqytxy.entity.*;

/**
 * 业务逻辑类
 *
 * @author yinjw
 */
public class Service {

    /**
     * 用刀
     *
     * @param gameRole  角色对象(引用传递)
     */
    public static void useKnife(GameRole gameRole) {
        Weapon knife = new Knife();
        knife.setAtt(10);
        knife.setName("大砍刀");
        // 对象类型强转
        Knife temp = (Knife) knife;
        temp.setLength(20);
        gameRole.setWeapon(knife);
        gameRole.useWeapon();
    }

    /**
     * 用枪
     *
     * @param gameRole  角色对象
     */
    public static void useGun(GameRole gameRole) {
        Weapon gun = new Gun();
        gun.setName("突击抢");
        gun.setAtt(100);
        Gun temp = (Gun) gun;
        temp.setNum(20);
        gameRole.setWeapon(temp);
        gameRole.useWeapon();
    }

    /**
     * 添加物品
     * @param gameRole  角色
     */
    public static void addItem(GameRole gameRole) {
        Item item = new FirstAidPacket();
        item.setName("补给包");
        Item[] items = gameRole.getItems();
        items[0] = item;
        System.out.println("添加成功！！");
    }

    /**
     * 查看物品
     * @param gameRole  角色
     */
    public static void viewItems(GameRole gameRole) {
        Item[] items = gameRole.getItems();
        System.out.println("用户名称为：" + gameRole.getName() + "的背包物品如下：");
        for (int i = 0; i < items.length; i++) {
            if (items[i] == null) {
                continue;
            }
            System.out.println(items[i].getName());
        }
    }
}
